package com.jf3q.front.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jf3q.common.domain.EduCourse;
import com.jf3q.common.domain.EduTeacher;
import com.jf3q.common.vo.ResultVo;
import com.jf3q.common.vo.TeacherVo;
import com.jf3q.front.service.TeacherService;
import com.jf3q.front.service.impl.CourseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    TeacherService teacherService;

    @Autowired
    CourseServiceImpl courseService;

    //讲师大咖
    @PostMapping("/TeacherMaster")
    public ResultVo getTeacherMaster(){
        //拿到前四条数据
        List<EduTeacher> teachers = teacherService.selectTeacherMaster();
        //判断集合有没有拿到讲师大咖的信息,并返回
        if (teachers != null){
            return new ResultVo(20000,"",teachers);
        }else {
            return new ResultVo(30000,"获取数据为空", null);
        }
    }

    //所有讲师
    @PostMapping("/TeacherList")
    public ResultVo getTeacherList(Integer pageNum,Integer pageSize){
        //拿到前端的分页页码
        PageHelper.startPage(pageNum,pageSize);
        //获取所有讲师数据,放入pageinfo中,再返回
        List<EduTeacher> list = teacherService.list();
        PageInfo pageInfo=new PageInfo(list);

        return new ResultVo(20000,"",pageInfo);

    }

    //讲师详情
    @GetMapping("/get/{id}")
    public ResultVo getTeacherById(@PathVariable String id){
        //根据id查询讲师信息,并查询主讲课程
        TeacherVo teacherVo = teacherService.selectTeacherById(id);

        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("teacher_id",id);
        List<EduCourse> list = courseService.list(queryWrapper);
        teacherVo.setCourseList(list);
        if (teacherVo != null){
            return new ResultVo(20000,"",teacherVo);
        }else {
            return new ResultVo(30000,"查询失败",null);
        }
    }









}
